package org.aaron.demos;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;

public class MyExpandableListActivity extends ExpandableListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listmainlayout);
		initActivity();
	}

	private void initActivity() {
		List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
		Map<String, String> group1 = new HashMap<String, String>();
		group1.put("test1", "test1");
		group1.put("test2", "test2");
		Map<String, String> group2 = new HashMap<String, String>();
		group2.put("test1", "test3");
		group2.put("test2", "test4");
		groupData.add(group1);
		groupData.add(group2);

		List<List<Map<String, String>>> childDatas = new ArrayList<List<Map<String, String>>>();
		List<Map<String, String>> childData = new ArrayList<Map<String, String>>();
		Map<String, String> child1 = new HashMap<String, String>();
		child1.put("test1", "test1");
		child1.put("test2", "test2");
		childData.add(child1);
		
		List<Map<String, String>> childData2 = new ArrayList<Map<String, String>>();
		Map<String, String> child2 = new HashMap<String, String>();
		child2.put("test1", "test3");
		child2.put("test2", "test4");
		childData2.add(child2);

		childDatas.add(childData);
		childDatas.add(childData2);
		ExpandableListAdapter adapter = new SimpleExpandableListAdapter(MyExpandableListActivity.this, groupData, R.layout.listgrouplayout, new String[] { "test1", "test2" }, new int[] { R.id.text1,
				R.id.text2 }, childDatas, R.layout.listchildlayout, new String[] { "test1", "test2" }, new int[] { R.id.text1, R.id.text2 });

		setListAdapter(adapter);

	}
}
